cmake_minimum_required(VERSION 3.10)
project(MySQLProject VERSION 1.0)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)




# set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -fPIC -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated-declarations -Wno-unused-result ")
# set(CMAKE_C_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -fPIC -ggdb -std=c11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated-declarations -Wno-unused-result ")

# 使用 pkg-config 查找 MySQL
find_package(PkgConfig REQUIRED)
pkg_check_modules(MYSQL REQUIRED mysqlclient)


include_directories(${MYSQL_INCLUDE_DIRS})
include_directories(.)
include_directories(/usr/include)

# 显示 MySQL 信息
message(STATUS "MySQL Include Dirs: ${MYSQL_INCLUDE_DIRS}")
message(STATUS "MySQL Libraries: ${MYSQL_LIBRARIES}")

# 添加可执行文件
add_executable(test_mysql_init test/test_mysql_init.cpp)
add_executable(test_mysql_connnect test/test_mysql_connnect.cpp)
add_executable(test_mysql_options test/test_mysql_options.cpp)
add_executable(test_mysql_query test/test_mysql_query.cpp)
add_executable(test_mysql_result test/test_mysql_result.cpp)
add_executable(test_mysql_featch_row test/test_mysql_featch_row.cpp)
add_executable(test_mysql_featch_field test/test_mysql_featch_field.cpp)
add_executable(test_mysql_insert test/test_mysql_insert.cpp)
# 包含 MySQL 头文件目录
target_include_directories(test_mysql_init PRIVATE ${MYSQL_INCLUDE_DIRS})
target_include_directories(test_mysql_connnect PRIVATE ${MYSQL_INCLUDE_DIRS})
target_include_directories(test_mysql_options PRIVATE ${MYSQL_INCLUDE_DIRS})
target_include_directories(test_mysql_query PRIVATE ${MYSQL_INCLUDE_DIRS})
target_include_directories(test_mysql_result PRIVATE ${MYSQL_INCLUDE_DIRS})
target_include_directories(test_mysql_featch_row PRIVATE ${MYSQL_INCLUDE_DIRS})
target_include_directories(test_mysql_featch_field PRIVATE ${MYSQL_INCLUDE_DIRS})
target_include_directories(test_mysql_insert PRIVATE ${MYSQL_INCLUDE_DIRS})
# 链接 MySQL 库
target_link_libraries(test_mysql_init ${MYSQL_LIBRARIES})
target_link_libraries(test_mysql_connnect ${MYSQL_LIBRARIES})
target_link_libraries(test_mysql_options ${MYSQL_LIBRARIES})
target_link_libraries(test_mysql_query ${MYSQL_LIBRARIES})
target_link_libraries(test_mysql_result ${MYSQL_LIBRARIES})
target_link_libraries(test_mysql_featch_row ${MYSQL_LIBRARIES})
target_link_libraries(test_mysql_featch_field ${MYSQL_LIBRARIES})
target_link_libraries(test_mysql_insert ${MYSQL_LIBRARIES})



set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
# 安装规则（可选）
#install(TARGETS my_mysql_app DESTINATION bin)
